package org.lanqiao.music.web.controller;

import org.lanqiao.music.common.utils.Result;
import org.lanqiao.music.system.entity.UserMusic;
import org.lanqiao.music.system.service.UserMusicService;
import org.lanqiao.music.system.vo.MusicVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/userMusic")
public class UserMusicController {

    @Autowired
    private UserMusicService userMusicService;

    //用户收藏的音乐列表
    @GetMapping("/favorites")
    public List<MusicVO> getUserFavoriteMusic(Integer userId) {
        return userMusicService.getUserFavoriteMusic(userId);
    }

    //添加收藏的音乐
    @PostMapping("/insert")
    public Result insert(@RequestBody UserMusic userMusic){
        int r = userMusicService.insert(userMusic);
        if(r == 1){
            return Result.success("添加成功");
        }
        return Result.fail("添加失败");
    }

    //取消收藏
    @GetMapping("/del")
    public Result deleteById(Integer musicId){
        int r = userMusicService.deleteById(musicId);
        if(r == 1){
            return Result.success("删除成功");
        }
        return Result.fail("删除失败");
    }
}
